package com.workflow.action;

import java.util.List;

import com.base.bean.Cardinfo;
import com.base.service.CardinfoService;
import com.base.service.DictService;
import com.common.bean.Datadict;
import com.common.util.PagerModel;
import com.common.util.StringToken;
import com.core.ssh2.AbstractActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.workflow.bean.Inputdeptdetail;
import com.workflow.service.InputcardService;
import com.workflow.service.InputdeptdetailService;

public class InputcardManagerAction extends AbstractActionSupport implements
		Preparable {
	private static final long serialVersionUID = -4291654982990736047L;

	private InputcardService inputcardService;
	
	private InputdeptdetailService inputdeptdetailService;
	
	private CardinfoService cardinfoService;
	
	private DictService dictService;
	
	private Inputdeptdetail inputdeptdetail;
	
	private Cardinfo cardinfo;
	
	private String intdetailno;
	
	private String cardno;
	
	private PagerModel pm;
	
	private List<Datadict> datadictByBasetypelist;
	
	private List<Datadict> datadictByAreatypelist;
	
	private List<Datadict> datadictByFuntypelist;
	
	private Datadict datadictByBasetype;

	private Datadict datadictByAreatype;

	private Datadict datadictByFuntype;
	
	private long money;
	
	private boolean selected;//是否是查看已选卡标识
	
	private long num;
	
	@SuppressWarnings("unchecked")
	public void prepare() throws Exception {
		//字典选项
		datadictByBasetypelist = dictService.findDictDetail(StringToken.DICT_CARD_BASETYPE);
		datadictByAreatypelist = dictService.findDictDetail(StringToken.DICT_CARD_AREATYPE);
		datadictByFuntypelist = dictService.findDictDetail(StringToken.DICT_CARD_FUNTYPE);
		num = inputcardService.findAllInputcardByIntdetailno(intdetailno).size();
	}
	
	@Override
	public String execute() throws Exception {
		inputdeptdetail = inputdeptdetailService.findInputdeptdetail(intdetailno);
		return SUCCESS;
	}
	
	public String addInputcard() throws Exception {
		inputcardService.addInputcard(cardno, intdetailno);
		return SUCCESS;
	}
	
	public String findCardinfoForIntdetailno() throws Exception {
		selected = false;
		inputdeptdetail = inputdeptdetailService.findInputdeptdetail(intdetailno);
//		根据三种类型、面额,子卡类型（志号）选卡（状态为初始状态，且所属部门为组织架构） 
		pm = cardinfoService.findCardinfoForPagerWith(datadictByBasetype.getTypeid(), 
				datadictByAreatype.getTypeid(), datadictByFuntype.getTypeid(),
				StringToken.DICT_CARDSTATUS_INIT, money,
				inputdeptdetail.getCardsubtype().getCardsubtypeno(),StringToken.DEPARTMENT_CARD_DEF/*默认组织架构*/);
		return SUCCESS;
	}
	
	public String findCardinfoInputSelected() throws Exception {
		selected = true;
		inputdeptdetail = inputdeptdetailService.findInputdeptdetail(intdetailno);
		pm = cardinfoService.findCardinfoForPagerWithBelongto(intdetailno, StringToken.DICT_CARDSTATUS_LOCK,
				inputdeptdetail.getCardsubtype().getCardsubtypeno(),StringToken.DEPARTMENT_CARD_DEF/*默认组织架构*/);
		return SUCCESS;
	}
	
	public String delInputcard() throws Exception {
		inputcardService.removeInputcard(cardno);//
		return SUCCESS;
	}

	/**
	 * @return the cardinfo
	 */
	public Cardinfo getCardinfo() {
		return cardinfo;
	}

	/**
	 * @param cardinfo the cardinfo to set
	 */
	public void setCardinfo(Cardinfo cardinfo) {
		this.cardinfo = cardinfo;
	}

	/**
	 * @return the cardinfoService
	 */
	public CardinfoService getCardinfoService() {
		return cardinfoService;
	}

	/**
	 * @param cardinfoService the cardinfoService to set
	 */
	public void setCardinfoService(CardinfoService cardinfoService) {
		this.cardinfoService = cardinfoService;
	}

	/**
	 * @return the cardno
	 */
	public String getCardno() {
		return cardno;
	}

	/**
	 * @param cardno the cardno to set
	 */
	public void setCardno(String cardno) {
		this.cardno = cardno;
	}

	/**
	 * @return the datadictByAreatype
	 */
	public Datadict getDatadictByAreatype() {
		return datadictByAreatype;
	}

	/**
	 * @param datadictByAreatype the datadictByAreatype to set
	 */
	public void setDatadictByAreatype(Datadict datadictByAreatype) {
		this.datadictByAreatype = datadictByAreatype;
	}

	/**
	 * @return the datadictByAreatypelist
	 */
	public List<Datadict> getDatadictByAreatypelist() {
		return datadictByAreatypelist;
	}

	/**
	 * @param datadictByAreatypelist the datadictByAreatypelist to set
	 */
	public void setDatadictByAreatypelist(List<Datadict> datadictByAreatypelist) {
		this.datadictByAreatypelist = datadictByAreatypelist;
	}

	/**
	 * @return the datadictByBasetype
	 */
	public Datadict getDatadictByBasetype() {
		return datadictByBasetype;
	}

	/**
	 * @param datadictByBasetype the datadictByBasetype to set
	 */
	public void setDatadictByBasetype(Datadict datadictByBasetype) {
		this.datadictByBasetype = datadictByBasetype;
	}

	/**
	 * @return the datadictByBasetypelist
	 */
	public List<Datadict> getDatadictByBasetypelist() {
		return datadictByBasetypelist;
	}

	/**
	 * @param datadictByBasetypelist the datadictByBasetypelist to set
	 */
	public void setDatadictByBasetypelist(List<Datadict> datadictByBasetypelist) {
		this.datadictByBasetypelist = datadictByBasetypelist;
	}

	/**
	 * @return the datadictByFuntype
	 */
	public Datadict getDatadictByFuntype() {
		return datadictByFuntype;
	}

	/**
	 * @param datadictByFuntype the datadictByFuntype to set
	 */
	public void setDatadictByFuntype(Datadict datadictByFuntype) {
		this.datadictByFuntype = datadictByFuntype;
	}

	/**
	 * @return the datadictByFuntypelist
	 */
	public List<Datadict> getDatadictByFuntypelist() {
		return datadictByFuntypelist;
	}

	/**
	 * @param datadictByFuntypelist the datadictByFuntypelist to set
	 */
	public void setDatadictByFuntypelist(List<Datadict> datadictByFuntypelist) {
		this.datadictByFuntypelist = datadictByFuntypelist;
	}

	/**
	 * @return the dictService
	 */
	public DictService getDictService() {
		return dictService;
	}

	/**
	 * @param dictService the dictService to set
	 */
	public void setDictService(DictService dictService) {
		this.dictService = dictService;
	}

	/**
	 * @return the inputcardService
	 */
	public InputcardService getInputcardService() {
		return inputcardService;
	}

	/**
	 * @param inputcardService the inputcardService to set
	 */
	public void setInputcardService(InputcardService inputcardService) {
		this.inputcardService = inputcardService;
	}

	/**
	 * @return the inputdeptdetail
	 */
	public Inputdeptdetail getInputdeptdetail() {
		return inputdeptdetail;
	}

	/**
	 * @param inputdeptdetail the inputdeptdetail to set
	 */
	public void setInputdeptdetail(Inputdeptdetail inputdeptdetail) {
		this.inputdeptdetail = inputdeptdetail;
	}

	/**
	 * @return the inputdeptdetailService
	 */
	public InputdeptdetailService getInputdeptdetailService() {
		return inputdeptdetailService;
	}

	/**
	 * @param inputdeptdetailService the inputdeptdetailService to set
	 */
	public void setInputdeptdetailService(
			InputdeptdetailService inputdeptdetailService) {
		this.inputdeptdetailService = inputdeptdetailService;
	}

	/**
	 * @return the intdetailno
	 */
	public String getIntdetailno() {
		return intdetailno;
	}

	/**
	 * @param intdetailno the intdetailno to set
	 */
	public void setIntdetailno(String intdetailno) {
		this.intdetailno = intdetailno;
	}

	/**
	 * @return the money
	 */
	public long getMoney() {
		return money;
	}

	/**
	 * @param money the money to set
	 */
	public void setMoney(long money) {
		this.money = money;
	}

	/**
	 * @return the num
	 */
	public long getNum() {
		return num;
	}

	/**
	 * @param num the num to set
	 */
	public void setNum(long num) {
		this.num = num;
	}

	/**
	 * @return the pm
	 */
	public PagerModel getPm() {
		return pm;
	}

	/**
	 * @param pm the pm to set
	 */
	public void setPm(PagerModel pm) {
		this.pm = pm;
	}

	/**
	 * @return the selected
	 */
	public boolean isSelected() {
		return selected;
	}

	/**
	 * @param selected the selected to set
	 */
	public void setSelected(boolean selected) {
		this.selected = selected;
	}
	
	
}
